<?php ob_start();?>
<?php
$root = $_SERVER['DOCUMENT_ROOT'];
include($root.'/standart/head.php');
include($root.'/standart/dateHeader.php');
include($root.'/standart/checkUser.php');
$db = connect();
if(isset($_GET["ID"]) && $_GET["ID"] != ''){
	if(isset($_GET["DELETE"])){
		$stmt ="DELETE FROM FIX_MENU
					WHERE ID = ?";
		$statement = $db->prepare($stmt);
		$statement->bind_param('i', $_GET["ID"]);
		if(!$statement->execute ()) {
			echo '<span style="color:red; font-weight:bolder;">İşlem sırasında hata alındı </span>';
		}
		$statement->close();
	}else{
		$menuId = $_GET["MENU"];
		$category = $_GET["CATEGORY"];
		$datex = $_GET["DATE"];
		
		$stmt ="UPDATE FIX_MENU
					SET MENU_ID = ?, 
						CATEGORY_ID = ?
					WHERE ID = ?";
		$statement = $db->prepare($stmt);
		$statement->bind_param('iii', $menuId, $category, $_GET["ID"]);
		if(!$statement->execute ()) {
			echo '<span style="color:red; font-weight:bolder;">İşlem sırasında hata alındı </span>';
		}
		$statement->close();
	}
}else{
	$menuId = $_GET["MENU"];
	$category = $_GET["CATEGORY"];
	$datex = $_GET["DATE"];
	list($gun,$ay,$yil) = explode('/',$datex);
	$yeni_tarih = $yil.'-'.$ay.'-'.$gun;
	
	$stmt ="INSERT INTO FIX_MENU (MENU_ID, CATEGORY_ID, MENU_DATE) 
				VALUES(?,?,?)";
	$statement = $db->prepare($stmt);
	$statement->bind_param('iis', $menuId, $category, $yeni_tarih);
	if(!$statement->execute()){
		echo '<span style="color:red; font-weight:bolder;">Kayıt sırasında hata alındı </span>';
	}
	$statement->close();
}
disconnect($db);
?>
<?php ob_end_flush(); ?>